Skip to content

Playwright: fix error in pytest_runtest_makereport hook #6604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions playwright_tests/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ def pytest_runtest_makereport(item, call) -> None:
If a test failure occurred (including pytest assertion failures) we are saving & attaching the
test execution screencast to the allure report for better debugging.
"""

outcome = yield # Capture the result of the test execution.
report = outcome.get_result() # Retrieve the test execution report.

# Ensure the test has failed and involves Playwright automation.
if report.failed and "page" in item.funcargs:
page: Page = item.funcargs["page"] # Retrieve the page object from the test function args.
video_path = page.video.path() # Retrieve the path to the recorded video.
page.context.close() # Close the browser context to ensure the video is properly saved.
# Ensure that the hook is executed during the test execution phase.
if call.when == "call":
report = outcome.get_result() # Retrieve the test execution report.

# Ensure the test has failed and involves Playwright automation.
if report.failed and "page" in item.funcargs:
page: Page = item.funcargs["page"] # Retrieve the page object from the test args.
video_path = page.video.path() # Retrieve the path to the recorded video.
page.context.close() # Close the browser context to ensure the video is saved.

# Attaching the video to the Allure report:
allure.attach(
open(video_path, 'rb').read(),
name=f"{slugify(item.nodeid)}.webm",
attachment_type=allure.attachment_type.WEBM
)
# Attaching the video to the Allure report:
allure.attach(
open(video_path, 'rb').read(),
name=f"{slugify(item.nodeid)}.webm",
attachment_type=allure.attachment_type.WEBM
)


@pytest.fixture()
Expand Down